﻿#region Using Directives

    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Csla;
    using Csla.Core;

#endregion

namespace MarketPulse.BusinessLogic.Core
{
    /// <summary>
    /// Base business objects collection class that all editable business objects i.e. those that would inherit
    /// directly from BusinessListBase, should inherit from.
    /// </summary>
    /// <typeparam name="T">Must be derived from MarketPulseListBase (this class)</typeparam>
    /// <typeparam name="C">Element of the collection.  Must be derive from MarketPulseReadOnlyBase</typeparam>
    [Serializable]
    public abstract class MarketPulseListBase<T, C> : BusinessListBase<T, C>
        where T : MarketPulseListBase<T, C>
        where C : MarketPulseBase<C>
    {

        /// <summary>
        /// Method used to find a single object from the collection based on the unique identifier supplied
        /// </summary>
        /// <param name="guid">The guid that uniquely identifies the object to find</param>
        /// <returns>A valid object (populated or empty)</returns>
        public C FindByGuid(Guid guid)
        {
            var result = (from item in this.Items
                          where item.GUID == guid
                          select item).Single();

            return (C)result;
        }
    }
}
